
/** 
  实习需求报名新增
*/
<style scoped>
.p_cals:hover{
  cursor: pointer;
  color: #409eff;
}
.p_cals{
  color: #aaa
}
</style>

<template>
  <div >
      <el-row type="flex" class="row-bg" justify="space-between">
        <div>
          <span @click="goBack" class="p_cals">{{$t('requirement.registration')}}</span> / <span>{{internshipDemand}}</span>
        </div>
        <!-- <el-button @click="cancelDialog" type="text">{{$t('requirement.back')}}</el-button> -->
      </el-row>
      <p></p>
      <el-card>
        <el-row type="flex" class="row-bg" justify="space-between">
          <h2>{{$t('requirement.practice')}}</h2>
            <!-- <el-row type="flex" class="row-bg" justify="end">
              <el-button @click="cancelDialog" >{{$t('requirement.back')}}</el-button>
              <el-button type="danger"  @click="conserve">{{$t('requirement.save')}}</el-button>
              <el-button type="danger"  @click="affirmForm" >{{$t('requirement.submit')}}</el-button>
            </el-row> -->
        </el-row>
        <hr style="border-top: 2px solid #eee;">
        <h3 style="margin-left:20px">{{$t('requirement.information')}}</h3>
        <div style="margin-left:20%" >

          <el-form :model="queryForm" label-width="140px"  :rules="rules" ref="addform"  label-suffix="：" >
            
            <el-row >
              <el-col :span="13">
                <el-form-item :label="$t('requirement.internship')" prop="baseName" >
                  <el-select   v-model="queryForm.baseName" clearable style="width: 100%">
                    <el-option
                        v-for="item in formsLearn"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                  </el-select> 
                  <!-- <el-input v-model="queryForm.baseName" maxlength="64" width='100%'></el-input> -->
                </el-form-item>
              </el-col>
            </el-row>
            <el-row >
              <el-col :span="13">
                <el-form-item :label="$t('requirement.namePost')" prop="positionName" >
                  <el-input v-model="queryForm.positionName" maxlength="64" width='100%'></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row >
              <el-col :span="13">
                <el-form-item :label="$t('requirement.college')" prop="collegeAcademy">
                    <DictSelect clearable 
                      v-model="queryForm.collegeAcademy"
                      :multiple="false"
                      filterable
                      :plzSelect="$t('internship.pleaseSelect')"
                      @change="collegeChange"
                      :data="options.faculty" >
                    </DictSelect>
                  </el-form-item>
              </el-col>
            </el-row>
            <el-row >
              <el-col :span="13">
                <el-form-item :label="$t('requirement.major')" prop="majorList">
                  <el-select collapse-tags v-model="queryForm.majorList" @change="professionChange" multiple filterable clearable style="width:100%" >
                    <el-option 
                        v-for="item in options.profession"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              
            </el-row>
            <el-row >
              <!-- <el-col :span="13"> -->
                <el-form-item :label="$t('requirement.demand')" prop="personNum">
                  <el-input-number v-model="queryForm.personNum" @change="handleChangeNum" :min="1" :max="10000"></el-input-number>
                </el-form-item>
              <!-- </el-col> -->
            </el-row>
            <el-row >
              <el-col :span="13">
                <el-form-item :label="$t('requirement.workplace')" prop="workAddress">
                  <el-input  v-model="queryForm.workAddress" maxlength="64"></el-input>
                  <!-- @change="changeEmail" -->
                </el-form-item>
              </el-col>
            </el-row>
            <el-row >
              <el-col :span="13">
                <el-form-item :label="$t('requirement.treatment')" prop="treatment">
                  <el-input  v-model="queryForm.treatment" maxlength="1000"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row >
              <el-col :span="13">
                <el-form-item :label="$t('requirement.workDate')" prop="workTimeStart">
                  <el-row type="flex" class="row-bg" justify="space-between">

                    <el-date-picker
                      v-model="queryForm.workTimeStart"
                      type="date"
                      :clearable="false"
                      :picker-options="pickerworkTimeStart"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      placeholder="选择日期时间">
                    </el-date-picker>
                    至
                    <el-date-picker
                      v-model="queryForm.workTimeEnd"
                      type="date"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      :clearable="false"
                      :picker-options="pickerworkTimeEnd"
                      placeholder="选择日期时间">
                    </el-date-picker>
                  </el-row>
                  <!-- <el-date-picker
                    v-model="queryForm.workTime"
                    type="daterange"
                    range-separator="至" style="width:100%"
                    start-placeholder="开始日期"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    end-placeholder="结束日期">
                  </el-date-picker> -->
                </el-form-item>
              </el-col>
            </el-row>
            <el-row >
              <el-col :span="13">
                <el-form-item :label="$t('requirement.requirement')" prop="majorRequirements">
                  <el-input
                    maxlength="1000"
                    type="textarea"
                    :rows="5"
                    v-model="queryForm.majorRequirements" >
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="13">
                <el-form-item :label="$t('requirement.semester')" prop="calendarYear">
                  <CalendarSelect :defaulted='false' v-model="queryForm.calendarYear" @change="changeSelect" @load-done="loadDone"></CalendarSelect>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row >
              <el-col :span="13">
                <el-form-item :label="$t('requirement.theTime')" prop="applyTimeStart">
                  <el-row type="flex" class="row-bg" justify="space-between">

                  <el-date-picker
                    v-model="queryForm.applyTimeStart"
                    type="datetime"
                    :clearable="false"
                    :picker-options="pickerOptionsStart"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    format="yyyy-MM-dd HH:mm:ss"
                    >
                  </el-date-picker>
                  至
                  <el-date-picker
                    v-model="queryForm.applyTimeEnd"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    format="yyyy-MM-dd HH:mm:ss"
                    :clearable="false"
                    :picker-options="pickerOptionsEnd"
                    >
                  </el-date-picker>
                  </el-row>
                  <!-- <el-date-picker style="width:100%"
                    v-model="queryForm.applyTime"
                    type="daterange"
                    @change="changeApplyTime"
                    range-separator="至"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期">
                  </el-date-picker> -->
                </el-form-item>
                <!-- <el-form-item :label="$t('graduate.semester')" prop="calendarYear">
                  <CalendarSelect v-model="queryForm.calendarYear" @change="changeSelect" @load-done="loadDone" @input='changeInput'></CalendarSelect>
                </el-form-item> -->
              </el-col>
            </el-row>
            
            <el-row >
              <el-form-item :label="$t('internship.adjunct')" prop="">
                <el-upload
                  class="upload-demo"
                  v-model="queryForm.enclosureFileName"
                  action="api/commonservice/obsfile/uploadfile"
                  :headers="{'X-Token': $store.state.session.sessionid}"
                  :data="{bucketname: 'face', folderpath: 'file'}"
                  :on-change="handleChange"
                  :on-remove="handleRemove"
                  :on-success="handleSuccess"
                  :limit="1"
                  :file-list="fileList">
                  <!-- 
                  :limit="3" enclosureFile-->
                  <el-button size="small" type="primary">{{$t('internship.selectFile')}}</el-button>
                  <!-- <div v-if='deleting' slot="tip" class="el-upload__tip">{{$t('internship.againDeleting')}}</div> -->
                  <div  slot="tip" class="el-upload__tip">{{$t('requirement.attachment')}}</div>
                </el-upload>
              </el-form-item>
            </el-row>
            <el-row type="flex" class="row-bg" justify="end">
              <el-button @click="cancelDialog" >{{$t('requirement.cancel')}}</el-button>
              <el-button type="danger"  @click="conserve">{{$t('requirement.save')}}</el-button>
              <el-button type="danger"  @click="affirmForm" >{{$t('requirement.submit')}}</el-button>
            </el-row>
          </el-form>
          <el-dialog
            width="25%"
            ref="innerDialog"
            :title="$t('graduateBase.prompt')"
            :visible.sync="innerVisible"
            append-to-body
            :top="'28vh'">
            <div style="text-align: left;margin-bottom: 25px;">{{$t('graduateBase.cancelTip')}}</div>
            <div style="text-align: right;">
              <el-button type="primary" @click="confirmInner">{{$t('common.btn.confirm')}}</el-button>
              <el-button @click="cancelInner">{{$t('common.btn.cancel')}}</el-button>
              <el-button type="primary" @click="confirmAndClose">{{$t('graduateBase.saveAndClose')}}</el-button>
            </div>
          </el-dialog>
        </div>
        <!-- <el-row type="flex" class="row-bg" justify="end">
          <el-button @click="cancelDialog" >{{$t('graduate.cancel')}}</el-button>
        
          <el-button type="danger"  @click="conserve">{{$t('graduate.conserve')}}</el-button>
          <el-button type="danger"  @click="affirmForm" >{{$t('graduate.submit')}}</el-button>
        </el-row> -->
    </el-card>
  </div>
</template>

<script>
import { queryDic } from "common/src/api/dictionary";
import UTILS from "common/src/utils/utils";
import graduateStudent from 'common/src/api/graduateStudent/graduateStudent';
export default {
  
  props: {
    
    dataListObj: {
      type: String
    },
    dataProp: {
      type: String
    },
    dataListProp: {
      type: Object
    },
    showFlag: {
      type: Boolean
    },
    agent: {
      type: Boolean,
      default: false,
      required: false
    },
    admin: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    
    let cannotDateEnter = (rule, value, callback) => {
      let reg = /[`$]/im;
      if (reg.test(value)) {
        return callback(new Error(this.$t('identificationToDoList.cannotContain')));
      } else if (value === '') {
        return callback(new Error(this.$t('internship.pleaseEnter')));
      }
      return callback();
    };
    let cannotEnter = (rule, value, callback) => {
      let reg = /[`$]/im;
      if (reg.test(value)) {
        return callback(new Error(this.$t('identificationToDoList.cannotContain')));
      }
      return callback();
    };
    let cannotNumEnter = (rule, value, callback) => {
      let reg = /^[1-9][0-9]*$/;
      // let reg = /^[1-9]*$/;
      if (!reg.test(value)) {
        return callback(new Error(this.$t('internship.positive')));
      }
      return callback();
    };
    return {
      dataList: [],
      fileList: [],
      collegeAcademy: 'collegeAcademy',
      innerVisible: false,
      deleting: false,
      queryForm: {
        // workTime: [],
        // applyTime: [],
        workTimeStart: null,
        workTimeEnd: null,
        applyTimeStart: null,
        applyTimeEnd: null,
        majorList: [],
        major: '',
        calendarYear: '',
        calendarTerm: '',
        calendarName: '',
        personNum: 1,
        enclosureFileUrl: '',
        enclosureFileName: '',
        status: '',
        positionName: '',
        baseName: '',
        workAddress: '',
        collegeAcademy: '',
        majorRequirements: '',
        treatment: ''
      },
      applyTimeEnd: '',
      applyTimeStart: '',
      internshipDemand: '实习需求报名新增',
      auths: [], // 按钮权限
      id: '',
      formsLearn: [],
      options: {
        faculty: [],
         profession: [],
        degreeType: []
      },
      pickerworkTimeStart: {
        disabledDate: time => {
          let endDateVal = this.queryForm.workTimeEnd;
          if (endDateVal) {
            // return time.getTime() > endDateVal;
            return time.getTime() > new Date(endDateVal).getTime();
          }
        }
      },
      pickerworkTimeEnd: {
        disabledDate: time => {
          let beginDateVal = this.queryForm.workTimeStart;
          if (beginDateVal) {
            // return time.getTime() < beginDateVal;
            return time.getTime() <= new Date(beginDateVal).getTime()- 86400000;
          }
        }
      },
      pickerOptionsStart: {
        disabledDate: time => {
          let endDateVal = this.applyTimeStart;
          let beginDateVal = this.queryForm.applyTimeEnd;
          if (beginDateVal) {
            let list = '';
            // if (this.$route.query.title === 'edit') {

            //   list = new Date(endDateVal).getTime()- 86400000;
            // } else {
            //   list = new Date(endDateVal).getTime();
            // }
            list = new Date(endDateVal).getTime();
            let times =  new Date(beginDateVal).getTime();
            return time.getTime() > times || time.getTime() < list;
          }
          // if (beginDateVal) {
          //   return time.getTime() > new Date(beginDateVal).getTime();
          //   // return time.getTime() > new Date(endDateVal).getTime() || time.getTime() > new Date(beginDateVal).getTime();
          // }
        }
      },
      pickerOptionsEnd: {
        disabledDate: time => {
          let beginDateVal = this.applyTimeEnd;
          let endDateVal = this.queryForm.applyTimeStart;
          if (beginDateVal) {
            let list = '';
            // if (this.$route.query.title === 'edit') {

            //   list = new Date(endDateVal).getTime()- 86400000;
            // } else {
            //   list = new Date(endDateVal).getTime();
            // }
            list = new Date(endDateVal).getTime();
            let times =  new Date(beginDateVal).getTime();
            return time.getTime() >times || time.getTime() < list;
          }
        }
      },
      rules: {
        baseName: [
          { required: true, message: this.$t('graduate.pleaseSelect'), trigger: 'change' }
        ],
        calendarYear: [
          { required: true, message: this.$t('graduate.pleaseSelect'), trigger: 'change' }
        ],
        workTimeStart: [
          { required: true, message: this.$t('graduate.pleaseSelect'), trigger: 'change' }
        ],
        applyTimeStart: [
          { required: true, message: this.$t('graduate.pleaseSelect'), trigger: 'change' }
        ],
        majorList: [
          { required: true, message: this.$t('graduate.pleaseSelect'), trigger: 'change' }
        ],
        enclosureFileName: [
          { required: true, message: this.$t('internship.attachment'), trigger: 'blur' } 
        ],
        treatment: [
          { validator: cannotEnter, trigger: 'blur' } 
        ],
        positionName: [
          { required: true, validator: cannotDateEnter, trigger: 'blur' } 
        ],
        workAddress: [
          { required: true, validator: cannotDateEnter, trigger: 'blur' } 
        ],
        personNum: [
          { required: true, validator: cannotNumEnter, trigger: 'change' } 
        ],
        majorRequirements: [
          { required: true, validator: cannotDateEnter, trigger: 'blur' } 
        ],
        collegeAcademy: [
          { required: true, message: this.$t('graduate.pleaseSelect'), trigger: 'change' } 
        ],
        
      },
      titleList: ''
      
    };
  },
  watch: {
    'titleList': {
      handler: function(newV, oldV) {
        // console.log(newV, '4545');
        // this.getSchoolCalendar();
        // if (newV === 'edit') {
        //   let dataRowList = JSON.parse(JSON.stringify(this.$route.query.row));
        //   // let dataRowList = this.$route.query.row;
        //   this.queryForm = dataRowList;
        //   graduateStudent.schoolCalendar().then(res => {
        //     this.dataList = res.data;
        //     this.dataList.forEach(el => {
        //       if (el.fullName === dataRowList.calendarName) {
        //         this.queryForm.calendarYear = el.id;
        //       }
        //     });
        //   });
        //   let collegeList = [];
        //   // console.log(dataRowList, 'dataRowList');
        //   collegeList.push(dataRowList.collegeAcademy);
        //   graduateStudent.getDegreeByCollege(collegeList).then(res => {
        //     this.options.profession = res.data;
        //     // this.queryForm.majorList = dataRowList.majorList;
        //     this.queryForm.majorList = dataRowList.major.split(',');
            
        //   });
        //   if (dataRowList.enclosureFileName) {
        //     this.fileList.push({ name: dataRowList.enclosureFileName });
        //     this.deleting = true;
        //   }
        //   // console.log(this.queryForm);
          
        //   this.applyTimeEnd = this.$route.query.row.applyTimeEnd;
        //   this.internshipDemand = this.$t('requirement.edit');
        // }
        // if (newV) {his.$route.query.title === 'edit'
        //   if (this.dataListProp) {
        //     if (this.dataProp === '新增') {
        //       this.fileList = [];
        //     } else {
        //       this.queryForm = JSON.parse(JSON.stringify(this.dataListProp));
        //       this.fileList.push({ name: this.dataListProp.enclosureFileName });
        //     }
        //   } 
        // } else {
        //   this.fileList = [];
        //   this.queryForm = {};
        // }
      }
    }
  },
  // async beforeCreate() {
  //   this.source.language = await kindo.util.getLanguage('certificateTypeLang');
  // },
  methods: {
    changeApplyTime(val) {
      // console.log(val, this.queryForm.applyTime);
    },
    // getSchoolCalendar() {
    //   graduateStudent.schoolCalendar().then(res => {
    //     // console.log(res);
    //     this.dataList = res.data;
    //   });
    // },
    // 获取学期
    getSchoolCalendar() {
      graduateStudent.schoolCalendar().then(res => {
        this.dataList = res.data;
      });
    },
    loadDone(data, val) {
      // console.log(data, val);
      this.dataList = data;
    },
    getSessionBase() {
      graduateStudent.getSession().then(res => {
        this.id = res.data.realUid;
      }).then(() => {
        this.getBaseListByBase(this.id);
      });
    },
    getBaseListByBase(id) {
      this.formsLearn = [];
      graduateStudent.getBaseListByBaseAccount(id).then(res => {
        // console.log(res, 'fsfs');
        if (res.data.length > 0) {

          res.data.forEach(el => {
            this.formsLearn.push({
              label: el.baseName,
              value: el.baseName
            }) 
          });

        }
      });
    },
    // 字典获取
    getOptions() {
      // 筛选条件字典查询
      let data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: ['G_ZY', 'X_YX']
      };
      queryDic(data).then(res => {
        UTILS.fillSelect(
          {
            degreeType: "G_ZY",
            faculty: "X_YX"
          },
          res.data,
          this.options
        );
      });
    },
    // 通过学院获取专业
    collegeChange(val) {
      this.queryForm.majorList = [];
      if (val.length > 0) {
        let collegeList = [];
        collegeList.push(val);
        graduateStudent.getDegreeByCollege(collegeList).then(res => {
          this.options.profession = res.data;
          this.controlDeclaration();
        });
      } else {
        this.options.profession = [];
      }
      
    },
    // 点击专业
    professionChange(val) {
      // this.queryForm.major = this.queryForm.majorList.length > 0 ? this.queryForm.majorList.join() : '';
      // console.log(val, this.queryForm.majorList, 'sdfd', this.queryForm.major);
      this.controlDeclaration();
    },
    goBack() {
      this.$store.commit("delete_tabs", this.$route.path);
      this.$router.go(-1)
    },
    // 岗位需求人数
    handleChangeNum (val) {
      // console.log(val, 'skjfds');
      
    },
    // 输入网址
    changeEmail(val) {
      // console.log(val);
      let re = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
      if (val) {
        if (re.test(val)) {
          return this.queryForm.baseContactEmail = val;
          // return true;
        }else{
          this.$message(this.$t('mainbase.pleasEmail'));
          this.queryForm.baseContactEmail = '';
        }
      }
    },
    // 校验学校联系人电话
    changeNum(val) {
      let reg = /^[1][3,4,5,7,8][0-9]{9}$/;
      if (val) {
        if (reg.test(val)) {
          return this.queryForm.collegeContactPhone = val;
          // return true;
        }else{
          this.$message(this.$t('mainbase.pleasePhone'));
          this.queryForm.collegeContactPhone = '';
        }
      }
    },
    changeSelect(val) {
      // console.log(val, '112');
      this.dataList.forEach(el => {
        if (val === el.id) {
          this.queryForm.calendarYear = el.year;
          this.queryForm.calendarTerm = el.term;
          this.queryForm.calendarName = el.fullName;
        }
      });
      this.controlDeclaration();
    },
    // 控制申报时间
    controlDeclaration() {
      if (this.queryForm.calendarYear&&this.queryForm.calendarTerm&&this.queryForm.majorList.length > 0&&this.queryForm.collegeAcademy) {
        // console.log('123');
        let obj = {};
        if (this.$route.query.title === 'edit') {
          this.dataList.forEach(el => {
            if (this.queryForm.calendarYear === el.id) {
              this.queryForm.calendarYear = el.year;
              this.queryForm.calendarTerm = el.term;
              this.queryForm.calendarName = el.fullName;
            }
            obj = {
              calendarYear: this.queryForm.calendarYear,
              calendarTerm: this.queryForm.calendarTerm,
              major: this.queryForm.majorList.length > 0 ? this.queryForm.majorList.join() : '',
              college: this.queryForm.collegeAcademy
            };
            // if (el.fullName === dataRowList.calendarName) {
            //   this.queryForm.calendarYear = el.id;
            // }
          });
        } else {
          obj = {
            calendarYear: this.queryForm.calendarYear,
            calendarTerm: this.queryForm.calendarTerm,
            major: this.queryForm.majorList.length > 0 ? this.queryForm.majorList.join() : '',
            college: this.queryForm.collegeAcademy
          };
        }
        graduateStudent.getSettingWhileAddPosition(obj).then(res => {
          if (res.data) {
            this.queryForm.applyTimeStart = res.data.signStart + ' ' + '00:00:00';
            this.queryForm.applyTimeEnd = res.data.signEnd + ' ' + '23:59:59';
            this.applyTimeEnd = res.data.signEnd + ' ' + '23:59:59';
            this.applyTimeStart = res.data.signStart + ' ' + '00:00:00';
          }
        }).catch(e =>{
            this.queryForm.applyTimeStart = null;
            this.queryForm.applyTimeEnd = null;
        });
      } else {
        this.queryForm.applyTimeStart = null;
        this.queryForm.applyTimeEnd = null;
      }
    },
    // changeCollege(val) {
    //   this.queryForm.collegeAcademy = '';
    //   if (val === '1') {
    //     this.rules.collegeAcademy[0].required = false;
    //   } else {
    //     this.rules.collegeAcademy[0].required = true;
    //   }
    // },
    // 内层弹出确定
    confirmInner() {
      this.innerVisible = false;
      // this.dataListProp = {};
      for (const key in this.queryForm) {
        if (this.queryForm[key] === 'applyTimeStart') {
          this.queryForm.applyTimeStart = null;
        } else if (this.queryForm[key] === 'workTimeEnd') {
          this.queryForm.workTimeEnd = null;
        } else if (this.queryForm[key] === 'applyTimeStart') {
          this.queryForm.applyTimeStart = null;
        } else if (this.queryForm[key] === 'applyTimeEnd') {
          this.queryForm.applyTimeEnd = null;
        } else if (this.queryForm[key] === 'majorList') {
          this.queryForm.majorList = [];
        } else if (this.queryForm[key] === 'personNum') {
          this.queryForm.personNum = 1;
        } else {
          this.queryForm[key] = "";
        }
      }
      this.fileList = [];
      this.$refs['addform'].resetFields();
      this.deleting = false;
      this.$store.commit("delete_tabs", this.$route.path);
      this.$router.go(-1);
    },
    // 内层弹出取消
    cancelInner() {
      this.innerVisible = false;
    },
    // 内层弹出保存关闭
    confirmAndClose() {
      this.innerVisible = false;
      this.conserve();
    },
    // 取消
    cancelDialog() {
      let isEmpty = true;
      for (let key in this.queryForm) {
        if (this.queryForm[key]) {
          isEmpty = false;
        }
      }
      if (isEmpty) {
        this.innerVisible = false;
        this.deleting = false;
        this.$store.commit("delete_tabs", this.$route.path);
        this.$router.go(-1);
        // this.$emit("cancel-dialog", false);
      } else {
        this.innerVisible = true;
      }
     
    },
    // 重置
    reset() {
      this.$emit("cancel-dialog", false);
    },
    // 提交
    affirmForm() {
      this.$refs['addform'].validate(valid => {
        if (valid) {
          if (this.queryForm.applyTimeStart > this.queryForm.applyTimeEnd) {
            return this.$message.warning(this.$t('requirement.declaration'));
          }
          if (this.$route.query.title === 'add') {
            this.queryForm.status = 1;
            this.queryForm.major = this.queryForm.majorList.length > 0 ? this.queryForm.majorList.join() : '';
            let obj = Object.assign({}, this.queryForm);
            obj.workTimeStartStr = this.queryForm.workTimeStart;
            obj.workTimeEndStr = this.queryForm.workTimeEnd;
            obj.applyTimeStartStr = this.queryForm.applyTimeStart;
            obj.applyTimeEndStr = this.queryForm.applyTimeEnd;
            delete obj.workTimeStart;
            delete obj.workTimeEnd;
            delete obj.applyTimeStart;
            delete obj.applyTimeEnd;
            graduateStudent.positionNeedsAddNeeds(obj).then(res => {
              this.goBack();
              this.deleting = false;
            });
          } else if (this.$route.query.title === 'edit') {
            this.dataList.forEach(el => {
              if (this.queryForm.calendarYear === el.id) {
                this.queryForm.calendarYear = el.year;
                this.queryForm.calendarTerm = el.term;
                this.queryForm.calendarName = el.fullName;
              }
            });
            this.queryForm.status = 1;
            this.queryForm.major = this.queryForm.majorList.length > 0 ? this.queryForm.majorList.join() : '';
            let obj = Object.assign({}, this.queryForm);
            obj.workTimeStartStr = this.queryForm.workTimeStart;
            obj.workTimeEndStr = this.queryForm.workTimeEnd;
            obj.applyTimeStartStr = this.queryForm.applyTimeStart;
            obj.applyTimeEndStr = this.queryForm.applyTimeEnd;
            delete obj.workTimeStart;
            delete obj.workTimeEnd;
            delete obj.applyTimeStart;
            delete obj.applyTimeEnd;
            graduateStudent.positionNeedsEdit(obj).then(res => {
              this.goBack();
              this.deleting = false;
            });
          }
        }
      });
    },
    // 保存
    conserve() {
      this.$refs['addform'].validate(valid => {
        if (valid) {
          if (this.queryForm.applyTimeStart > this.queryForm.applyTimeEnd) {
            return this.$message.warning(this.$t('requirement.declaration'));
          }
          if (this.$route.query.title === 'add') {
            this.queryForm.status = 0;
            this.queryForm.major = this.queryForm.majorList.length > 0 ? this.queryForm.majorList.join() : '';
            let obj = Object.assign({}, this.queryForm);
            obj.workTimeStartStr = this.queryForm.workTimeStart;
            obj.workTimeEndStr = this.queryForm.workTimeEnd;
            obj.applyTimeStartStr = this.queryForm.applyTimeStart;
            obj.applyTimeEndStr = this.queryForm.applyTimeEnd;
            delete obj.workTimeStart;
            delete obj.workTimeEnd;
            delete obj.applyTimeStart;
            delete obj.applyTimeEnd;
            graduateStudent.positionNeedsAddNeeds(obj).then(res => {
              this.goBack();
              this.deleting = false;
            });
          } else if (this.$route.query.title === 'edit') {
            this.dataList.forEach(el => {
              if (this.queryForm.calendarYear === el.id) {
                this.queryForm.calendarYear = el.year;
                this.queryForm.calendarTerm = el.term;
                this.queryForm.calendarName = el.fullName;
              }
            });
              this.queryForm.status = 0;
              this.queryForm.major = this.queryForm.majorList.length > 0 ? this.queryForm.majorList.join() : '';
              let obj = Object.assign({}, this.queryForm);
              obj.workTimeStartStr = this.queryForm.workTimeStart;
              obj.workTimeEndStr = this.queryForm.workTimeEnd;
              obj.applyTimeStartStr = this.queryForm.applyTimeStart;
              obj.applyTimeEndStr = this.queryForm.applyTimeEnd;
              delete obj.workTimeStart;
              delete obj.workTimeEnd;
              delete obj.applyTimeStart;
              delete obj.applyTimeEnd;
            graduateStudent.positionNeedsEdit(obj).then(res => {
              this.goBack();
              this.deleting = false;
            });
          }
        }
      });
      // }
    },
    // 上传之前
    handleChange() {},
    // 删除
    handleRemove() {
      this.queryForm.enclosureFileName = '';
      this.queryForm.enclosureFileUrl = '';
      this.deleting = false;
    },
    // 上传成功
    handleSuccess(res, file, fileList) {
      // console.log(res, file, fileList);
      this.fileList = fileList
      this.queryForm.enclosureFileName = 'a';
      this.deleting = true;
      this.setInformationAttachList(fileList);
    },
    setInformationAttachList(fileList) {
      let attachList = [];
      fileList.forEach(item => {
        if (item.response && item.response.data) {
          const uploadedObj = item.response.data[item.name];
          if (uploadedObj) {
            // const attachObj = {};
            // attachObj.fileName = uploadedObj.fileName;
            // attachObj.fileLacation = uploadedObj.objectkey;
            // attachList.push(attachObj);
            this.queryForm.enclosureFileName = uploadedObj.fileName;
            this.queryForm.enclosureFileUrl = uploadedObj.objectkey;
          }
        }
      });
      // return attachList;
    }
    
  },
  mounted() {
    this.getSessionBase();
    this.getSchoolCalendar();
    this.getOptions();
    this.titleList = this.$route.query.title;
  },
  // async
  created() {
    if (this.$route.query.title === 'add') {
      this.internshipDemand = this.$t('requirement.add');
    } else {
      let dataRowList = JSON.parse(JSON.stringify(this.$route.query.row));
      this.queryForm = dataRowList;
      graduateStudent.schoolCalendar().then(res => {
        this.dataList = res.data;
        this.dataList.forEach(el => {
          if (el.fullName === dataRowList.calendarName) {
            this.queryForm.calendarYear = el.id;
          }
        });
      });
      let collegeList = [];
      collegeList.push(dataRowList.collegeAcademy);
      graduateStudent.getDegreeByCollege(collegeList).then(res => {
        this.options.profession = res.data;
        // this.queryForm.majorList = dataRowList.majorList;
        this.queryForm.majorList = dataRowList.major.split(',');
        
      });
      if (dataRowList.enclosureFileName) {
        this.fileList.push({ name: dataRowList.enclosureFileName });
        this.deleting = true;
      }
      this.applyTimeEnd = this.$route.query.row.applyTimeEnd;
      this.applyTimeStart = this.$route.query.row.applyTimeStart;
      this.internshipDemand = this.$t('requirement.edit');
    }
  }
};
</script>
